
import Api from '@/services/api';
import { checkPhoneNumber } from '@/utils/utils';
export default {
  data() {
    return {
      userName: '', // 分销商姓名
      phone: '', // 手机号
      isTeam: 0, // 是否是团队
      isTeamStr: '个人', // 是否是团队文案
      typeArr: [{ // 分销商类型数组
        key: 0,
        val: '个人'
      }, {
        key: 1,
        val: '团队'
      }]
    }
  },
  onShow() {
  },
  computed: {
    privacyData() {
      return this.$store.state.privacyData;
    }
  },
  mounted() {
  },
  methods: {
    handlePickerPop(e) {
      const { arr, value } = e.currentTarget.dataset;
      this.$refs.commonPickerPop.togglePopup(true, { arr, value })
    },
    // 弹窗确认事件
    onConfirm({ key, val }) {
      this.isTeam = key;
      this.isTeamStr = val;
    },
    // 按钮提交事件
    handleSubmit() {
      if (!this.userName) {
        return uni.showToast({ title: '请输入姓名', icon: 'none' })
      }
      if (!this.phone) {
        return uni.showToast({ title: '请输入联系电话', icon: 'none' })
      }
      if (!checkPhoneNumber(this.phone)) {
        return uni.showToast({ title: '请输入正确的联系电话', icon: 'none' })
      }

      this.applyDistribution();
    },
    // 申请成为分销商
    async applyDistribution() {
      const { code, result } = await this.$request({
        url: Api.applyToBecomeaDistributor,
        method: 'POST',
        data: {
          userName: this.userName,
          phone: this.phone,
          isTeam: this.isTeam
        }
      });
      if (code === 200) {
        uni.showToast({ title: '提交申请成功', icon: 'none' });
        setTimeout(() => {
          uni.navigateBack();
        }, 500)
      }
    }
  }
}